package com.example.videopractice.other

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import java.io.File

class CustomView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    private val bitmap: Bitmap
    private val paint = Paint()
    init {
        paint.isAntiAlias = true //抗锯齿
        paint.style = Paint.Style.STROKE //仅描边

        val path = context.cacheDir.absolutePath + File.separator + "image.jpg"
        bitmap = BitmapFactory.decodeFile(path)
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        // 不建议在onDraw做任何分配内存的操作
        canvas?.drawBitmap(bitmap, 0f, 0f, paint);
    }
}